home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Testing & Debugging / Virtual User tools / SPEC S&L v.1.0.1 / Libraries / StandardFile.Lib < prev    next >
Encoding:
Text File  |  1993-12-17  |  30.5 KB  |  823 lines  |  [TEXT/MPS ]

  1. #
  2. # ****************************************************************************
  3. #
  4. #    File Name:    StandardFile.Lib
  5. #
  6. #    Contains:    Tasks that support Standard File operations.
  7. #
  8. #    Written by:    Kevin Avoy, Ken Landreth, Michael Leong, Gil Spencer et al
  9. #
  10. #    Copyright:    © 1993 by Apple Computer, Inc., all rights reserved.
  11. #
  12. # ****************************************************************************
  13. #            C h a n g e        H i s t o r y (most recent first):
  14. # ****************************************************************************
  15. #
  16. #        Vers      Date        Author        Description
  17. #        ----    --------    ------    ---------------------------------------------
  18. #     <1.0.27>    12/16/93    KTA        ModifyDocument was not returning correct values.
  19. #     <1.0.26>    12/14/93    KTA        Changed the way ModifyDocuemtn handles return values.
  20. #     <1.0.25>    12/13/93    KTA        OpenFile returns the name of the file it opened.
  21. #     <1.0.24>    11/19/93    NAGA    modify TCS format
  22. #     <1.0.23>     10/05/93    KTA        Revert() - Added longer wait before trying to dismiss dialog and 
  23. #                                    support for hierachical menus
  24. #     <1.0.22>     10/05/93    KTA        ModifyDocument() - Change returnVal to a 1 if it was successful.
  25. #     <1.0.21>     9/30/93    KTA        SaveAs() - Updated the output after saving a document.
  26. #     <1.0.20>     9/28/93    KTA        ModifyDocument() - Added TCS - 'Modify a Document'
  27. #     <1.0.19>     9/28/93    KTA        ModifyDocument() - Handle problem caused if gModifyDocument hook doesn't return a value
  28. #     <1.0.18>     9/22/93    KTA        Renamed gSaveOtherFormat -> SaveAsHook1,  gEndTimer -> SaveAsHook2
  29. #                                    gDismissSFPut -> gSaveAsHook3,gOpenFileHook -> gOpenFileHook1, 
  30. #                                    gEndTimer ->gOpenFileHook2, Removed pParameter1 from OpenFile()
  31. #     <1.0.17>     9/14/93    KTA        SaveAs() - gCustomRetrievedDoc wasn't being used 
  32. #                                    because it was not defined as global.
  33. #     <1.0.16>     9/9/93        KTA        Removed all slang phrases from output.
  34. #     <1.0.15>     8/30/93    KTA        Updated task headers and parameters.
  35. #     <1.0.14>     8/25/93    KTA        Added support for parity checking the TCS stack.
  36. #     <1.0.13>     7/30/93    KTA        IsStandardFile - return window descriptor, ModifyDocument return
  37. #                                    success/Failure. Openfile better check if standardfile gone.
  38. #     <1.0.12>     7/23/93    KTA        SaveAs() - moved gDismissSFPut to before we verify filename.
  39. #     <1.0.11>     7/22/93    KTA        Fixed bugs with file name verificaton, SaveAS(), OpenFile().
  40. #     <1.0.10>     7/19/93    KTA        FindWindow() now supports descriptors - updated references.
  41. #     <1.0.9>     7/15/93    KTA        Added undefined task reference - gReplaceExisting.  Hook to
  42. #                                    handle a custom "replace existing?" dialog. This was done for Lotus 123.
  43. #     <1.0.8>     7/14/93    KTA        International Support: See SaveAs(), OpenFile(),
  44. #                                    CancelStandardFile(), Revert(), and Save().
  45. #     <1.0.7>      7/6/93    KTA        CustomRetrieveDoc change had a syntax error
  46. #     <1.0.6>      7/6/93    KTA        Performance Support
  47. #        <1+>     5/21/93    NAGA    Adding header and porting old files to follow new standards
  48. #
  49. # ****************************************************************************
  50. #
  51.  
  52. ########################################################################
  53. #                            External libraries 
  54. #=======================================================================
  55. Libraries "String.Lib","TCS.Lib","Output.Lib","UserInterface.Lib";
  56.  
  57.  
  58.  
  59.  
  60. #########################################################################
  61. #            SaveAs(pNameDoc, pReplaceFlag, pSelectSaveAs, pPathlist)
  62. #========================================================================
  63. # Author:        KTA
  64. # Description:    This routine will type a name (pNameDoc) into the text edit
  65. #                field.  Then it will press the ReturnKey to save the file.
  66. #                If there is a document already named <pNameDoc> a dialog will
  67. #                appear. If the <pReplaceFlag> evaluates to false
  68. #                it will select NO to 'Replace Existing?' dialog. It will
  69. #                then type the time (based on a 24 hour clock) after the
  70. #                name and retype the ReturnKey. The Default is to replace
  71. #                an existing document with the same name. It will also call
  72. #                getNewFileName to create a file name if one is not provided.
  73. # Parameters:    pNameDoc - string holding the name to name the document
  74. #                pReplaceFlag - 0 to select 'No' to 'Replace Existing' dialog
  75. #                              1 to select 'Yes' to replace exisiting file.
  76. #                pSelectSaveAs - Flag which indicates whether or not to select
  77. #                                SaveAs menuItem. 
  78. #                                0 - Do not select SaveAs MenuItem
  79. #                                1 - Select the SaveAs menuItem
  80. #                                {List} - Select the SaveAs menuItem using the 
  81. #                                        ord specified. e.g. {5,2}
  82. #                pPathlist - Path to navigate before saving - should be complete path.
  83. # Returns:        0 - Unable to dismiss SFPut or never present to begin with
  84. #                1 - Dismissed SFPut ok, saved file, ReplaceExist not called
  85. #                2 - Dismissed SFPut ok, saved file, ReplaceExist called
  86. # Examples:        SaveAs('Untitled1'); to name the file 'Untitled1'
  87. # Assumptions:    That the SF_Put dialog is present
  88. #     
  89. #========================================================================
  90. # History:
  91. # KTA    7/06/93        Performance Support: EndTimer
  92. # KTA    7/07/93        Ability to pass in saveAs menu, if pSelectSaveAs is list of menuItems
  93. # KTA    7/13/93        Added undefined task reference gReplaceExisitng
  94. # KTA    7/19/93        Changed call to FindWindow() to pass a descriptor.
  95. # KTA    7/22/93        if can't match (gActualFileName) reassign to string we typed
  96. # KTA    8/24/93        TCS stack parity check
  97. # KTA    9/14/93        gCustomRetrievedDoc wasn't being used because it was not
  98. #                    defined as global
  99. # KTA    9/22/93        Changed gSaveOtherFormat to gSaveAsHook1
  100. #                     Changed gEndTimer to gSaveAsHook2
  101. #                     Changed gDismissSFPut to gSaveAsHook3
  102. # KTA    9/30/93        Updated the output after saving a document.
  103. #########################################################################
  104. TASK SaveAs(pNameDoc := "", pReplaceFlag := true, pSelectSaveAs := False, pPathlist := global gSFPUTLocation) 
  105. begin
  106.     global gIsSys7, gLastSavedFile, gActualFileName;
  107.     returnVal := 0;
  108.     
  109.     if (pSelectSaveAs)
  110.     begin
  111.         TCSStart({ 1, global kTCSetSFSave },"SaveAs");                        # Start TCS
  112.         if(typeOf(pSelectSaveAs) = 'list')
  113.             thisReturn := selectmenuItem(pSelectSaveAs[1],pSelectSaveAs[2]);
  114.         else
  115.             thisReturn := selectmenuItem("Save As", "File");
  116.         TCSEnd({ 1, global kTCSetSFSave },thisReturn);        # Select the MenuItem
  117.     end;
  118.  
  119.     wait(2);
  120.     ## Check to see if Standard File is present
  121.     if (IsStandardFile()) 
  122.     begin
  123.         SFPutDesc:= match[window o:1]!;    #    Save off the descriptor
  124.         
  125.         LogStr("############## Standard File - Save  ##############");
  126.         if (pNameDoc = "") 
  127.             pNameDoc := GetNewFileName();    #To get a name    
  128.     
  129.         if (pPathlist) and (IsSys7)      # No navigating in 6.0
  130.             SFNavigate( pPathlist ,1);
  131.         
  132.         if (global gSaveAsHook1)        # app specific hook 
  133.             call (gSaveAsHook1);        # Useful for saving in other formats 
  134.     
  135.         TypeStr(pNameDoc);        # Type the name of the Document
  136.         SpecialKey(ReturnKey, 'Return Key');    # Accept the SF dialog
  137.         
  138.         wait(3);
  139.         if (global gReplaceExisting)
  140.             Call(gReplaceExisting,pReplaceFlag,pNameDoc);
  141.         else
  142.         begin
  143.             ## 7.0 and 6.0 have different 'Replace Existing' dialogs
  144.             ## Determine if Replace Existing Dialog is present
  145.             ReplaceExisting := collect[button w:[window o:1]];        
  146.             if (Card(ReplaceExisting) = 2)
  147.             begin
  148.                 pNameDoc := ReplaceExist(pReplaceFlag, pNameDoc);
  149.                 returnval:= 2;
  150.             end;
  151.             else 
  152.                 DialogCheck("",1);    # Look for other problems 
  153.         end;
  154.         
  155.         if (global gSaveAsHook2)            # app specific hook 
  156.             Call (gSaveAsHook2);            # This can be useful in performance testing
  157.             
  158.         if not FindWindow(SFPutDesc)        # if we can't find SFPut Dialog, indicates saved document for 1st time
  159.             if not returnval                # if not already reset from replace exist
  160.             begin
  161.                 returnVal := 1;                # set to success - no replace exist done
  162.                 TCSStart({ 2, global kTCSetSFSave },"Save a new file");
  163.                 TCSEnd({ 2, global kTCSetSFSave },1);
  164.             end; # if not returnval
  165.                 
  166.         if (global gSaveAsHook3)                # app specific
  167.             call (gSaveAsHook3);                # hook for handling anything
  168.         
  169.         if (returnval)
  170.         begin
  171.             gLastSavedFile := pNameDoc;
  172.             if (global gCustomRetrievedDoc)
  173.                 theFile := FindWindow(gCustomRetrievedDoc);
  174.             else
  175.                 theFile := FindWindow(0);
  176.                 
  177.             gActualFileName := theFile.t;
  178.             if(gActualFileName)
  179.                 str := "The document's window is named - '{gActualFileName}'";
  180.             else
  181.             begin
  182.                 gActualFileName := pNameDoc;
  183.                 str := "The document is named - '{gActualFileName}'";
  184.             end;
  185.             LogStr(str);
  186.         end;
  187.         else
  188.             logstr('Unable to dismiss the SFPut Dialog');
  189.         
  190.     end; # if (IsStandardFile())
  191.     
  192.     return(returnVal);
  193. end; # SaveAs()
  194.  
  195. #########################################################################
  196. #        OpenFile(pNameDoc,pSelectOpen, pPathList, pPartialPath)
  197. #========================================================================
  198. # Author:        KTA
  199. # Description:    This routine will select 'Open' from the 'File' menu, type
  200. #                the string held in the pNameDoc parameter, and
  201. #                then press the returnkey.  It will check to see that
  202. #                the frontmost window's title contains pNameDoc.  If not,
  203. #                it assumes that the wrong file opened.  It will not select
  204. #                'Open' if the pSelectOpen parameter is false.
  205. # Parameters:    pNameDoc - string name of document to open
  206. #                pSelectOpen - 0 to disable selecting of the 'Open' menu item.
  207. #                             1 to select 'Open' from the 'File' menu
  208. #                             2 keyEq - 'o'
  209. #                            list - list containing ordinality of 'Open' menuItem.
  210. #                pPathList - list defining path if file named <pNameDoc> not in
  211. #                        the current directory
  212. #                pPartialPath := Whether to start navigation at the current dir or 
  213. #                                at the desktop
  214. #                            1 - start at current directory
  215. #                            0 - start at desktop (not partial)
  216. # Returns:        1 - Document opened OK
  217. #                0 - Document not opened OK
  218. # Assumptions:    Works with SF_Get, but don't have pNameDoc be to long
  219. #                of a string.
  220. # Examples:        OpenFile('Untit'); will select a document such as 'Untitled'.
  221. #========================================================================
  222. # History:
  223. # KTA    7/06/93        Performance support: OpenFileHook, EndTimer and 
  224. #                    modified gCustomRetrievedDoc check
  225. # KTA    7/07/93        Ability to pass in open menu, if pSelectOpen is list of menuItems
  226. #                     Added global Actualfile so that we can do a better check to see if 
  227. #                    the right file was opened. (intl)
  228. # KTA    7/22/93        added isSubString(pNameDoc,DocName) better filename verification
  229. # KTA    7/29/93        Changed check for StandardFile being Present
  230. # KTA    8/24/93        TCS stack parity check
  231. # KTA    9/9/93        Removed the slang 'BuckWheat' from the output line.
  232. # KTA    9/22/93        Changed gOpenFileHook to gOpenFileHook1
  233. #                     Changed gEndTimer to gOpenFileHook2
  234. #                     Removed gTimedEvent
  235. #########################################################################
  236. TASK OpenFile(pNameDoc := "", pSelectOpen := 1, pPathList :={}, pPartialPath := 0) 
  237. begin    
  238.     global gIsSys7, gActualFileName;
  239.     returnVal := 0;
  240.     failStr := "";
  241.     if(pNameDoc)
  242.     begin
  243.         TCSStart({ 1, global kTCSetOpenDoc },"OpenFile");        # Start TCS
  244.     
  245.         if (pSelectOpen) 
  246.         begin
  247.             if (Typeof(pSelectOpen) = 'list') 
  248.                 selectmenuItem(pSelectOpen[1], pSelectOpen[2]);    # Select the Open menuItem for intl
  249.             else if (pSelectOpen = 1) 
  250.                 selectmenuItem("Open", "File");    # Select the Open menuItem
  251.             else if (pSelectOpen = 2) 
  252.                 KeyEq('o');                        # Keyboard equivelant 'o' for open
  253.         end;    
  254.         wait(2);
  255.         SFDialog := IsStandardFile();
  256.         if (SFDialog) 
  257.         begin
  258.             LogStr( "############## Standard File - Open  ##############");
  259.             if ( pPathList ) and (global gIsSys7)    # No navigating in 6.0
  260.                 SFNavigate(pPathList,,,pPartialPath);
  261.             
  262.             if(global gOpenFileHook1)
  263.                 call (gOpenFileHook1);                # Hook to do whatever required prior to typing filename
  264.             
  265.             TypeStr(pNameDoc);                        # Type the name of the file to open
  266.  
  267.             SpecialKey(ReturnKey, 'Return Key');    # Accept the dialog
  268.             
  269.                 if(global gOpenFileHook2)
  270.                     Call(gOpenFileHook2);        # Hook can be used for Performance
  271.             Wait(3);
  272.             
  273.             #### Check to make sure Standard file is no longer present
  274.             if (FindWindow(SFDialog))         # Call but don't log that it's not there
  275.             begin
  276.                 failStr := "!@#$% Standard File is still present and it shouldn't be";
  277.                 LogStr(failStr);
  278.                 KeyEq('.');                # Exit (changed from 'cancel' button - intl)
  279.             end;
  280.             else if (global gCustomRetrievedDoc)
  281.             begin
  282.                 customDoc := match gCustomRetrievedDoc!;
  283.                 if(customDoc)
  284.                 begin
  285.                     DocName := customDoc.t;
  286.                     LogStr("The front window is named '{DocName}'");
  287.                     returnVal := 1;                        # return success
  288.                 end;
  289.                 else begin
  290.                     failStr := "!@#$% It appears that the wrong file was opened - {DocName}";
  291.                     LogStr(failStr);
  292.                 end;
  293.             end; # else if global gCustomRetrievedDoc
  294.             else # else do default doc checking
  295.             begin
  296.                 ### match the top document window (Hopefully the Document that was just opened)
  297.                 theDoc := findWindow(0);        # Match the document window
  298.                 DocName := theDoc.t;
  299.                 if not(DocName)
  300.                     LogStr("!@#$% No open window with grow and zoom boxes");
  301.                 else
  302.                     LogStr("The front document is named '{DocName}'");
  303.                 
  304.                 ## Is the document the one we expected
  305.                 if (isSubString(DocName,gActualFileName) or isSubString(pNameDoc,DocName))        # looks like the right file
  306.                     returnVal := 1;                        # return success
  307.                 else
  308.                 begin
  309.                     failStr := "!@#$% It appears that the wrong file was opened - {DocName}";
  310.                     LogStr(failStr); 
  311.                 end;
  312.             end; #  else do default doc checking
  313.         end; # if (IsStandardFile())
  314.         TCSEnd({ 1, global kTCSetOpenDoc },returnVal,failStr,,{DocName});
  315.     end;
  316.     else
  317.         LogStr("!@#$% No file name was specified");
  318.  
  319.     return(returnVal);
  320. end;  # OpenFile()
  321.  
  322. #########################################################################
  323. #            SFNavigate(pPathList, pTEToggle, pFinalReturn, pPartialPath)    
  324. #========================================================================
  325. # Author:        KTA
  326. # Description:    Controls the navigation in Standard File. 
  327. #                Assigns a global gSFOriginalPath to the current directory 
  328. #                for return navigation.
  329. #                Passes all parameters to SFType which performs actual navigation.
  330. # Parameters:    pPathList := List of directories beginning with the disk name.
  331. #                pTEToggle := Whether toggling from a text edit field is required 
  332. #                            to navigate.
  333. #                            1 - Toggle
  334. #                            0 - No toggling required
  335. #                pPartialPath := Whether to start navigation at the current dir or 
  336. #                                at the desktop
  337. #                            1 - start at current directory
  338. #                            0 - start at desktop
  339. #                pFinalReturn := Whether to accept the final item in <pPathList>
  340. # Returns:        PathList
  341. #========================================================================
  342. # History:
  343. #
  344. #########################################################################
  345. TASK SFNavigate( pPathList :={},pTEToggle :=0, pFinalReturn := 1, pPartialPath := 0) 
  346. begin
  347.     # Verify that Standard File is present
  348.     if (IsStandardFile()) 
  349.     begin
  350.         if (pPathList)    # Path list needs to be specified
  351.         begin        
  352.             OrigPathList :={};                        # Initialize variable    
  353.             match[popup i:?Popupitems];                # match SF popup 
  354.             
  355.             for x := 1 to (card PopUpItems-1)        # Build a Pathlist 
  356.                 OrigPathList := insert(PopUpItems[x].t,1,OrigPathList);
  357.     
  358.             if (OrigPathList = pPathList)            # Is the current directory the desired directory
  359.                 pPathList := {};
  360.             else if (TypeOf(pPathList) = "integer")     # return to where you started
  361.             begin
  362.                 if (pPathList = 1)     
  363.                     pPathList := Global gSFOriginalPath;
  364.             end;
  365.             else                                     # Update the gobal gSFOriginalPath
  366.                 gSFOriginalPath := OrigPathList;
  367.             
  368.             SFPath := '';
  369.             For each item in pPathList                 # For logging purposes - build pathlist
  370.                 SFPath := SFPath + Item + ":";
  371.             LogStr( "Standard File Navigation to the path - ∂[{SFPath}∂]",3);
  372.             
  373.              SFType(pPathList,pTEToggle, pFinalReturn, pPartialPath);
  374.             Return(pPathList);
  375.         end;
  376.         else
  377.             LogStr( "Standard File is set to current default directory",3);
  378.     end;
  379.     else
  380.         return(0);
  381. end; # SFNavigate()
  382.  
  383. #########################################################################
  384. #            SFType(pPathList, pTEToggle, pFinalReturn, pPartialPath)    
  385. #========================================================================
  386. # Author:        KTA
  387. # Description:    Performs navigation in Standard File.
  388. #                If <pPartialPath> evaluates to true Selects the 'DeskTop' button.
  389. #                Then types each item in <pPathList>
  390. #                folled by a returnKey.
  391. # Parameters:    pPathList := List of directories beginning with the disk name.
  392. #                pTEToggle := Whether toggling from a text edit field is required 
  393. #                            to navigate.
  394. #                            1 - Toggle
  395. #                            0 - No toggling required
  396. #                pPartialPath := Whether to start navigation at the current dir or 
  397. #                                at the desktop
  398. #                            1 - start at current dir
  399. #                            0 - start at desktop
  400. #                pFinalReturn := Whether to accept the final item in <pPathList>
  401. # Returns:        Nada
  402. #========================================================================
  403. # History:
  404. #
  405. #########################################################################
  406. TASK SFType(pPathList,pTEToggle :=0, pFinalReturn := 1, pPartialPath := 0)
  407. begin
  408.     if not (pPartialPath)
  409.         SelectButton('Desktop');
  410.     if (pTEToggle)
  411.         type k:{TabKey};        # Makes directory list active
  412.     wait(2);
  413.     TypeList(pPathList,1,pFinalReturn);    # Actual navigation
  414.     if (pTEToggle)
  415.         type k:{TabKey};        # Makes text edit  active
  416. end; # SFType()
  417.  
  418. #########################################################################
  419. #            ReplaceExist( pReplaceFlag,pNameDoc)    
  420. #========================================================================
  421. # Author:        KTA
  422. # Description:    Handles the 'Replace existing?' dialog.
  423. # Parameters:    pReplaceFlag - Whether to Replace a document with the same name
  424. #                        or generate a unique name.
  425. #                        1 - Overwrite document with same name.
  426. #                        0 - Do not overwrite.  Generate unique name.
  427. #                pNameDoc := Name of file which already exists on disk.
  428. # Returns:        pNameDoc ( will be identical to the initial one if pReplaceFlag is set)
  429. #========================================================================
  430. # History:
  431. # KTA    8/24/93        TCS stack parity check
  432. #########################################################################
  433. TASK ReplaceExist( pReplaceFlag := true, pNameDoc :='') 
  434. begin
  435.     global gIsSys7;
  436.     LogStr("    -- Replace Existing?? --");
  437.     # Different button names on dialog
  438.      myButton := collect[button w:[window o:1]];
  439.     firstButton := MyButton[1];
  440.     secondButton := MyButton[2];
  441.     if (firstButton.r[1] < secondButton.r[1])
  442.     begin
  443.         CancelString := firstButton.t;
  444.         ReplaceString := secondButton.t;
  445.     end;
  446.     else
  447.     begin
  448.         ReplaceString := firstButton.t;
  449.         CancelString := secondButton.t;
  450.     end;
  451.  
  452.     if (pReplaceFlag)        # Want to replace
  453.     begin
  454.         TCSStart({ 4, global kTCSetSFSave },"ReplaceExisting");        # Start TCS
  455.         if(SelectButton(ReplaceString))
  456.             returnVal := 1;
  457.         else
  458.             returnVal := 0;
  459.         TCSEnd({ 4, global kTCSetSFSave }, returnVal);
  460.     end;
  461.     else 
  462.     begin                    # Don't want to replace
  463.         TCSStart({ 3, global kTCSetSFSave },"CancelNewName");        # Start TCS
  464.         if(SelectButton(CancelString))
  465.             returnVal := 1;
  466.         else
  467.             returnVal := 0;
  468.             
  469.         TimeString := GetNewFileName(pNameDoc);
  470.         pNameDoc := "{pNameDoc}{TimeString}";
  471.         if(gIsSys7)        # 7.0 and 6.0 handle text entry differently in SF
  472.             type k:{rightArrowKey};        # Places I beam after existing text in SF text edit
  473.         TypeStr("{TimeString}");        # append time to pNameDoc in 6.0/7.0
  474.         SpecialKey(returnKey, 'Return key');
  475.         TCSEnd({ 3, global kTCSetSFSave },returnVal);
  476.     end;
  477.     return(pNameDoc);
  478. end; # ReplaceExist()
  479.  
  480. #########################################################################
  481. #                            GetNewFileName(pFileName, pIncludeNameFlag)    
  482. #========================================================================
  483. # Author:        SL
  484. # Description:    Gets a new file name by concatenating the app name and
  485. #                the current time.
  486. # Parameters:    pFileName -    If this parameter is present, this routine will
  487. #                        only pass back the time.  If this parameter is not
  488. #                        present, then this routine will pass back a string
  489. #                        consisting of the application name with the time
  490. #                        appended to it.
  491. #                pIncludeNameFlag - if true will append time and Sec to end of 
  492. #                            name and return it.
  493. # Returns:        newFileName - string name for new file name
  494. #                    or just a time and Sec string
  495. #========================================================================
  496. # History:
  497. #
  498. #########################################################################
  499. TASK GetNewFileName(pFileName :="",pIncludeNameFlag := 0) begin
  500.     Global IsSys7;
  501.     match [time h:?Tm s:?Sc];
  502.     if (pFileName)
  503.     begin 
  504.         if(pIncludeNameFlag)
  505.             newFileName := "{pFileName} {Tm}{Sc}"; 
  506.         else 
  507.             newFileName := " {Tm}{Sc}"; 
  508.     end;
  509.     else 
  510.     begin
  511.         match [Application t:?appName];
  512.         newFileName := "@!@{appName}-{Tm}{Sc}";
  513.     end;
  514.     return(newFileName);
  515. end; # GetNewFileName()
  516.  
  517. #########################################################################
  518. #             SFSelectPopupMenuItem(pPopupMenuItem) 
  519. #========================================================================
  520. # Author:        Kevin Avoy
  521. # Description:    Selects the popup menu item <pPopupMenuItem> from the Standard
  522. #                File dialog.
  523. # Parameters:    pPopupMenuItem -    The ordinality or Title of the menuitem (where
  524. #                                the Displayed menuItem is ord 1 if using Ordinality).
  525. # Returns:        nothing
  526. # Examples:        SelectPopupMenuItem("Font");
  527. #                SelectPopupMenuItem(2);
  528. # Assumptions:    The popup menu is in window ord 1
  529. #========================================================================
  530. # History:
  531. #
  532. #########################################################################
  533. TASK SFSelectPopupMenuItem( pPopupMenuItem := '')
  534. begin
  535.     if (IsStandardFile()) 
  536.     begin
  537.         PopupMenu := match[popup R:?ThePopUpRect i:?PopupMenuItems];
  538.         if (pPopupMenuItem = 0)
  539.             return(1);
  540.         x := ((ThePopUpRect[1]+ThePopUpRect[3])/2);
  541.         y := ((ThePopUpRect[2]+ThePopUpRect[4])/2);
  542.         
  543.         if not(TypeOf(pPopupMenuItem) = 'integer') 
  544.         begin
  545.             Match[MenuItem t:/{pPopupMenuItem}≈/ o:?PopUpOrd m:[Popup]];
  546.             pPopupMenuItem := PopUpOrd;
  547.         end;
  548.     
  549.         ### do our own logging
  550.         temp := global gDisableAllLogging;
  551.         global gDisableAllLogging := 1;
  552.         ### Now select menuitem
  553.         MoveMouse(x,y);
  554.         pressMouse;
  555.         wait(1);
  556.         move r: { 0,16 * (pPopupMenuItem - 1) };
  557.         wait(1);
  558.         releaseMouse;
  559.     
  560.         ### restore logging
  561.         global gDisableAllLogging := temp;
  562.         thePopupName := PopupMenuItems[pPopupMenuItem].t;
  563.     
  564.         ### log what just happened
  565.         LogStr("Selected popup menu item ∂'{thePopupName}∂' from the Standard File popUp");
  566.         Return(thePopupName);
  567.     end;
  568.     else 
  569.         return(0);
  570. end;
  571.  
  572. #########################################################################
  573. #                        ModifyDocument()
  574. #========================================================================
  575. # Author:        KTA
  576. # Description:    This task is called to modify a document so a revert to saved can
  577. #                be performed.  If a global tqask reference (gModifyDocument) is 
  578. #                defined, it will be called. Otherwise the default of typing a
  579. #                string will be used.
  580. # Parameters:    none
  581. # Returns:        0 - failure
  582. #                1 - success
  583. # Examples:        ModifyDocument()
  584. # Assumptions:    
  585. #========================================================================
  586. # History:
  587. # KTA    7/30/93     Added returnVal and return
  588. # KTA    9/28/93     isUndefined(returnVal)
  589. # KTA    9/28/93     Added TCS - 'Modify a Document'
  590. # KTA    10/05/93 Change returnVal to a 1 if it was successful
  591. # KTA    12/14/93 gModifyDoc can return a -1 and test was unsuccessful
  592. #########################################################################
  593. TASK ModifyDocument()
  594. begin
  595.     TCReturnVal := 0;
  596.     ErrStr := "";
  597.     TCSStart({ 1, global kTCSetRevertDoc }, "Modify a Document");
  598.     if (global gModifyDocument)
  599.     begin
  600.         TCReturnVal := call (gModifyDocument);
  601.         if(isUndefined(TCReturnVal))        # If the gModifyDocument hook doesn't return a value
  602.         begin
  603.             ErrStr := "Failed because there was no return value";
  604.             TCReturnVal := 0;        # no value returned from hook - have to fail.
  605.         end;
  606.         
  607.         if(TCReturnVal < 1)        # if gModifyDoc was successFul
  608.             returnVal := 0;        # return a failure
  609.         else
  610.             returnVal := 1;        # return a success
  611.     end;
  612.     else
  613.     begin
  614.         TypeStr("If 'Revert' worked, this shouldn't be here!");
  615.         TCReturnVal := 1;        #Hopefully this works to modify the document
  616.         returnVal := 1;        # return a success
  617.     end;
  618.     TCSEnd({ 1, global kTCSetRevertDoc }, TCReturnVal, ErrStr);
  619.     return(returnVal);
  620. end;
  621.  
  622. #########################################################################
  623. #                        Revert(pRevertMI)
  624. #========================================================================
  625. # Author:        KTA
  626. # Description:    If RevertMI is defined as the menuItem for revert it will be selected.
  627. #                Otherwise a menuItem with the word 'Revert' in it will be selected. 
  628. #                A dialog will normally appear confirming the revert request.  
  629. #                Several methods will be used when attempting to dismiss the dialog.
  630. #                Attempts to matck buttons "OK", "Yes", "Revert", are made, then 
  631. #                typing the returnKey.  If RevertMi is defined then DialogCheck()
  632. #                Will be called to output the static text in the dialog and the type
  633. #                the returnKey.
  634. # Parameters:    pRevertMI - List containing the ordinality of the revert menuItem. 
  635. # Returns:        nada
  636. # Examples:        Revert()
  637. # Assumptions:    
  638. #========================================================================
  639. # History:
  640. # KTA    7/12/93        Pass in pRevertMI for intl
  641. # KTA    8/24/93        TCS stack parity check
  642. # KTA    10/15/93    Added longer wait before trying to dismiss dialog and 
  643. #                    support for hierachical menus
  644. #########################################################################
  645. TASK Revert(pRevertMI := '')
  646. begin
  647.     global gApptitle;
  648.     returnVal := 0;
  649.     failStr := '';
  650.     TCSStart({ 2, global kTCSetRevertDoc },"Revert");        # Start TCS
  651.     if (pRevertMI = '')
  652.     begin
  653.         if(match [menu t:'File' i:{ [menuItem t:/Revert≈(≈∂n≈)*/ e:true o:?ord] } ]!)
  654.         begin
  655.             match [menu t:'File' i:{ [menuItem t:?item e:true o:ord] } ]!;
  656.             SelectMenuItem(item,'File');
  657.             if match [button t:'OK']
  658.                 SelectButton('OK');
  659.             else if match [button t:'Yes']
  660.                 SelectButton('Yes');
  661.             else if match [button t:'Revert']
  662.                 SelectButton('Revert');
  663.             else        # try default if no 'yes' or 'OK' button
  664.                 SpecialKey(returnKey, 'Return key');
  665.             DialogReturn := DialogCheck("",1);
  666.             if(DialogReturn)
  667.                 failStr := DialogReturn;
  668.             else
  669.                 returnVal := 1;
  670.         end;
  671.     end;
  672.     Else if(TypeOf(pRevertMI) = 'list')    # Pass in Ord for (Intl)
  673.     begin
  674.         if (Card(pRevertMI) = 2)
  675.             returnVal := SelectMenuItem(pRevertMI[1], pRevertMI[2]);
  676.         else if (Card(pRevertMI) = 3)
  677.             returnVal := SelectMenuItem(pRevertMI[1], pRevertMI[2], pRevertMI[3]);
  678.         Wait(2);
  679.         DialogCheck("",1);            # Dismiss the Revert Dialog
  680.     end;
  681.     else
  682.     begin
  683.         failStr := "There is no enabled menu item titled 'Revert' in {gApptitle}";
  684.         logstr(failStr);
  685.     end;
  686.     TCSEnd( { 2, global kTCSetRevertDoc }, returnVal, failStr);
  687. end;
  688.  
  689. #########################################################################
  690. #                        IsStandardFile(pLogIt)
  691. #========================================================================
  692. # Author:        KTA
  693. # Description:    Checks to see if the Standard File dialog is present
  694. # Parameters:    pLogIt - Flag indicating whether or not to output
  695. #                        the nonexistence of the StandardFile dialog.
  696. # Returns:        1 - if the Standard File dialog is present
  697. #                0 - if the Standard File dialog is not present
  698. # Examples:        IsStandardFile()
  699. # Assumptions:    
  700. #========================================================================
  701. # History:
  702. # KTA    7/7/93    Added enhanced check for StandardFile for intl systems
  703. # KTA    7/29/93    If StandardFile return a window descriptor of front window
  704. #########################################################################
  705. TASK IsStandardFile(pLogIt := 1)
  706. begin
  707.     returnVal := 0;
  708.     SF_Dialog := match[button t:/≈Desktop≈/]!;
  709.     if (SF_Dialog)
  710.         returnVal := match[window o:1]!;
  711.     else
  712.     begin
  713.         NumButtons :=  collect[button];
  714.         NumUserItem :=  collect[useritem];
  715.         if((Card(NumButtons) >= 4) and (Card(NumUserItem) >= 1))
  716.         returnVal := match[window o:1]!;
  717.     end;
  718.     if not(returnVal) and (pLogIt)
  719.         LogStr( "The Standard_File dialog is not present");
  720.  
  721.     return(returnVal);
  722. end;
  723.  
  724. #########################################################################
  725. #                        CancelStandardFile(pHowCancel, pSaveAsMenu)
  726. #========================================================================
  727. # Author:        KTA
  728. # Description:    Selects Save As and Cancels it
  729. # Parameters:    pHowCancel - method to cancel
  730. #                    0 := KeyEq('.');
  731. #                    1 := selectButton('Cancel');
  732. #                    2 := SpecialKey(escapeKey,"Escape key");
  733. #                pSaveAsMenu     -  list containing the ordinality of 'Save As' menu item.
  734. #                            - anything else will cause the hardcoded string 'Save As'
  735. #                                to be use in matching the menuItem.
  736. # Returns:        1 - if cancelling occured as expected
  737. #                0 - if it didn't
  738. # Examples:        CancelStandardFile()
  739. # Assumptions:    
  740. #========================================================================
  741. # History:
  742. # KTA    7/8/93    Added pHowCancel method 2 := escapekey
  743. # KTA    7/8/93    Added pSaveAsMenu the SaveAs menu descriptor
  744. # KTA    8/24/93    TCS stack parity check
  745. #########################################################################
  746. TASK CancelStandardFile(pHowCancel := 0, pSaveAsMenu := 0)
  747. begin
  748.     failStr := "";
  749.     returnVal := 0;
  750.     
  751.     if(pHowCancel = 1)
  752.         TCSNum := 5;    
  753.     else
  754.         TCSNum := 6;    
  755.         
  756.     TCSStart({ TCSNum, global kTCSetSFSave },"SaveAs/Cancel");        # Start TCS
  757.     if (TypeOf(pSaveAsMenu) = 'list')
  758.         SelectMenuItem(pSaveAsMenu[1],pSaveAsMenu[2]);        ## Save/Cancel
  759.     else
  760.         SelectMenuItem("Save As",'File');        ## Save/Cancel
  761.     wait(3);
  762.     if(IsStandardFile())                    # Check to see if standard file is present
  763.     begin
  764.         if(pHowCancel = 0)
  765.             KeyEq('.');
  766.         else if(pHowCancel = 1)
  767.         begin
  768.             if (match[button t:'Cancel'])
  769.                 selectButton('Cancel');                # Cancel the Standard SF_Put Dialog
  770.             else 
  771.             begin
  772.                 SpecialKey(escapeKey,"Escape key");    # Help insure success - (intl)
  773.                 failStr := "No 'Cancel' button found - Hit the escape key instead.";
  774.             end;
  775.         end;
  776.         else if(pHowCancel = 2)
  777.             SpecialKey(escapeKey,"Escape key");
  778.  
  779.         if not(IsStandardFile(0))                    # Check to see if standard file is not present
  780.             returnVal := 1;
  781.         else
  782.             failStr := "Standard_File is still present and shouldn't be";
  783.     end;
  784.     TCSEnd({ TCSNum, global kTCSetSFSave }, returnVal,failStr);    
  785.     return(returnVal);
  786. end;
  787.  
  788. #########################################################################
  789. #                        Save(pSaveMethod)
  790. #========================================================================
  791. # Author:        KTA
  792. # Description:    Selects Save - calls Save As if Standard File appears
  793. # Parameters:    pSaveMethod - Method to save
  794. #                    1 := Save from File Menu
  795. #                    2 := Command-'s'
  796. # Returns:        Nothing
  797. # Examples:        Save()
  798. # Assumptions:    
  799. #========================================================================
  800. # History:
  801. # KTA    7/8/93    Added pSaveMethod input parameter & pSaveMethod(2)
  802. # KTA    8/24/93    TCS stack parity check
  803. #########################################################################
  804. TASK Save(pSaveMethod := 1)
  805. begin
  806.     if(pSaveMethod = 1)
  807.     begin
  808.         if (match[menuItem t:'Save' m:[menu t:'File' e:true] e:true]!)
  809.         begin
  810.             TCSStart({ 7, global kTCSetSFSave },"Save using Save menu item");        # Start TCS
  811.             TCSEnd({ 7, global kTCSetSFSave }, SelectMenuItem("Save",'File'));    
  812.             if(isStandardFile(0))    # if StandardFile is present
  813.             begin
  814.                 SaveAs();            # Call SF handler
  815.             end;
  816.         end;
  817.         else
  818.             pSaveMethod := 2;    # Help insure success (intl)
  819.     end;
  820.     if(pSaveMethod = 2)
  821.         keyEq('s');
  822. end;
  823.